import React, {Component} from 'react'
import { Button, Form, Input, Alert} from 'antd'
import { connect } from 'react-redux';
import formItemLayout  from '../../constant/formItemLayout';

import * as actions from '../../action/index';
import {FormattedMessage} from "react-intl";

const FormItem = Form.Item;

class NodeBBAccountEditor extends Component {
    handleSubmitClick = (e) => {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
            this.props.updateNodeBBUser(values)
        });
    };

    render = () => {
        const {getFieldDecorator} = this.props.form;

        return (
            <Form className="login-form">
                <FormItem>
                        <Alert message={<FormattedMessage id='请绑定已有的论坛账号和密码' />} type="warning" showIcon/>
                </FormItem>

                <FormItem {...formItemLayout}
                          label={<FormattedMessage id='论坛账号' />}>
                    {getFieldDecorator('username', {
                        rules: [{required: true, message: 'Please input your username!'}],
                    })(
                        <Input placeholder="Username"/>
                    )}
                </FormItem>

                <FormItem {...formItemLayout}
                          label={<FormattedMessage id='论坛密码' />}>
                    {getFieldDecorator('password', {
                        rules: [{required: true, message: 'Please input your Password!'}],
                    })(
                        <Input type="password" placeholder="Password"/>
                    )}
                </FormItem>
                <FormItem>
                    <Button type="primary" htmlType="submit" onClick={this.handleSubmitClick}><FormattedMessage id='提交' /></Button>
                </FormItem>
            </Form>
        )

    };
}

const WrappedNodeBBAccountEditor = Form.create()(NodeBBAccountEditor);

const mapStateToProps = state => ({
    user: state.user,
    nodeBBEditInfo: state.nodeBBEditInfo
});

const mapDispatchToProps = dispatch => ({
    updateNodeBBUser: (nodeBBUser) => {
        dispatch(actions.updateNodeBBUser(nodeBBUser));
    }
});


export default connect(mapStateToProps, mapDispatchToProps)(WrappedNodeBBAccountEditor);

